package org.zebra.trans.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.zebra.trans.core.DefaultDictTranslation;
import org.zebra.trans.core.handler.TranslationBeanSerializerModifier;

/**
 * @author zhanghongbin
 */
@AutoConfiguration
public class TranslationConfig implements InitializingBean {

    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void afterPropertiesSet() {
        objectMapper.setSerializerFactory(
                objectMapper.getSerializerFactory().withSerializerModifier(new TranslationBeanSerializerModifier()));
    }

    @Bean
    @ConditionalOnMissingBean
    public DefaultDictTranslation defaultDictTranslation() {
        return new DefaultDictTranslation();
    }
}
